package cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//import javax.servlet.http.Cookie;

/**
 * @author Mc.Chai
 * @program: JavaWeb
 * @create 2022-03-24-15:29 15:29
 */
@WebServlet("/myCookie")
public class MyCookie extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("myCookie start....");
        javax.servlet.http.Cookie[] cookies = request.getCookies();
        if (cookies!=null){
            for (javax.servlet.http.Cookie cookie : cookies) {
                String name = cookie.getName();
                String value = cookie.getValue();
                System.out.println(name+":"+value);
            }
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
